
package com.example.tests;

 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;
import static org.testng.Assert.assertEquals;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

@SuppressWarnings("unused")
public class GroupCreationTests extends TestBase  {
	
  @Test(dataProvider = "randomValidGroupGenerator")
  public void testGroupCreationWithValidData(GroupData group) throws Exception {
	app.getNavigationHelper().openMainPage();
	app.getNavigationHelper().gotoGroupPage();
	
	// save old state
	
	List<GroupData> oldList = app.getGroupHelper().getGroups();
	
	//actions
	app.getGroupHelper().initGroupCreation();
    //GroupData group = new GroupData();
    //group.name = "groupname 1";
    //group.header = "header 1";
    //group.footer = "footer 1";
	
	app.getGroupHelper().fillGroupForm(group);
    app.getGroupHelper().submitGroupCreation();
    app.getGroupHelper().returnToGroupPage();
    
    // save new state
    
    List<GroupData> newList = app.getGroupHelper().getGroups();
        
    // compare states
   // assertEquals (newList.size(), oldList.size() + 1);
    
    oldList.add(group);
    Collections.sort(oldList);
    assertEquals(newList, oldList);
  }


  @Test
public void testEmptyGroupCreation() throws Exception {
  app.getNavigationHelper().openMainPage();
  app.getNavigationHelper().gotoGroupPage();
  
    //save old state
	List<GroupData> oldList = app.getGroupHelper().getGroups();
	
	// actions
  app.getGroupHelper().initGroupCreation();
  GroupData group = new GroupData("", "", "");
  app.getGroupHelper().fillGroupForm(group);
  app.getGroupHelper().submitGroupCreation();
  app.getGroupHelper().returnToGroupPage();
  
   //save new state
    List<GroupData> newList = app.getGroupHelper().getGroups();
    
 // compare states
    // assertEquals (newList.size(), oldList.size() + 1);
     
     oldList.add(group);
     Collections.sort(oldList);
     assertEquals(newList, oldList);
}
}
